<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=utf-8">
<script type="text/javascript" src="console.js"></script>
<script type="text/javascript" src="json2.js"></script>
<script type="text/javascript">

window.addEventListener("load", init, false);
// 1.makeWebSockets and WebWorkers instance
<?sjs
document.writeln('var ws = new WebSocket("ws://'+pow_server.REQUEST_HOST+':10081/");');
?>
var worker = new Worker("sockets.js");

function init() {
	// 2.show total result from workers
	worker.addEventListener("message", function(e) {
		var objResult = JSON.parse(e.data);
		p('Result('
			+objResult.platform+'/'
			+objResult.version.replace(/ .+$/,"")+'/'
			+objResult.name+'): '
			+objResult.result);
		p('ExecTime: '+addFigure(String(objResult.elapse)));
	}, false);

	// 3.get data from server and put it to workers
	ws.onmessage = function(msg) {
		p("Data(From Srv): "+msg.data);
		worker.postMessage(msg.data);
	};
}

function sendData(a){
	p("Data(To Srv): "+a);
	
	// print for chrome console!
	console.info(a);
	
	ws.send(a);
};

function addFigure(str){
	var num = str.replace(/,/g, "");
	while(num != (num = num.replace(/^(-?\d+)(\d{3})/, "$1,$2")));
	return num;
};

</script>
<title>Web Workers</title>
</head>
<body>
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
<p>
code:<br/>
<textarea type="text" id="test"></textarea>
<form>
<button onclick="sendData(document.getElementById('test').value);return false;"> 
send</button> 
</form>
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
</body>
</html>